'''
Created on Apr 28, 2010

@author: aortlieb
'''
if __name__=='__main__':
    import sys
    #sys.path.append('') # FIXME: get sarl on the path

from report.tools import *
from reportlab.lib.units import inch
import datetime

import myDatabase

############ PAGES ###############

class appointmentLabelPage(page):
    class settings:
        width=2.5*inch
        height=1*inch
        fontSize=7
        fontWidth=4 # FIXME: Determine automatically from the font data somehow.
        fontFiles=[("VeraMono","VeraMono.ttf"),]    
        
    LastName            = field(1.5,1+.85*inch,16, map='Account.LastName')
    FirstName           = field(xClearLeft(LastName,4) , 1+.85*inch , 10, map='Account.FirstName')
    Sex                 = field(xClearLeft(FirstName,4), 1+.85*inch , 1, map='Account.Sex')
    DOB                 = field(xClearLeft(Sex,4),      1+.85*inch  , 10, map='Account.DOB')
    
    AddressStreet       = field(1.5,1+.7*inch,44, map='Account.AccountDetail.AddressStreet')
    AddressCity         = field(1.5,1+.6*inch,12, map='Account.AccountDetail.AddressCity')
    AddressState        = field(xClearLeft(AddressCity,4),AddressCity.y, 2 , map='Account.AccountDetail.AddressState')
    AddressZip          = field(xClearLeft(AddressState_val,4),AddressCity.y,10, map='Account.AccountDetail.AddressZip')
    Phone               = field(xClearLeft(AddressZip,4),AddressCity.y,   14 , map='Account.Phone')
    AppointmentDate     = field(1.5,1+.45*inch,10, map='AppointmentDate')
    AppointmentTime     = field(xClearLeft(AppointmentDate,4),AppointmentDate.y, 7 , map='AppointmentTime')
    AppointmentDuration = field(xClearLeft(AppointmentTime, 4),AppointmentDate.y, 10 , map='AppointmentDuration')
    
    AppointmentType     = field(1.5,1+.25*inch,4, map='Appointment.Template.Name')
    AccountNumber       = field(xClearLeft(AppointmentType,4),ReasonCode.y,36, map='Account.AccountNumber')
    
    InsurerName         = field(1.5,1+.15*inch,44, map='Account.PrimaryInsurance.InsurerName')


############ REPORTS ##############

class appointmentLabelReportNextDayBatch(report):
    filename = 'appointmentlabelbatch.pdf'
    pages   =   [(appointmentLabelPage,15),]
    def query(self,params):
        # We don't need params here, but it has to be there for compliance with the class report
        tomorrow = datetime.date.today() + datetime.timedelta(days=1)
        q = myDatabase.session.query(myDatabase.Appointment)
        q = q.filter(myDatabase.Appointment.AppointmentDate == tomorrow)
        return q
    copies_per_result = 15
    
class appointmentLabelReport(customReport):
    filename = 'appointmentlabel.pdf'
    pages = [(appointmentLabelPage,15),]
    def query(self,params):
        q = myDatabase.session.query(myDatabase.Appointment)
        q = q.filter(myDatabase.Appointment.id == str(params['AppointmentID']))   
        return q 
    
